using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Xml;

namespace PocketLibrary
{
    public class BlogPost
    {
        public string postId = "-1";
        public string postTitle = "";
        public string postBody = "";
        public string publish = "";
        public string userId = "";
        public Category postCategory;
        public string ServiceEdit = "";
        public bool SaveAsDraft = false;

        public BlogPost() { }

        public BlogPost(string title, string body)
        {
            this.postTitle = title;
            this.postBody = body;
        }

        public void Lataa(string tiedosto)
        {
            using (StreamReader sr = new StreamReader(tiedosto))
            {
                StringBuilder sb = new StringBuilder();
                postTitle = sr.ReadLine();
                while (sr.Peek() != -1)
                {
                    sb.Append(sr.ReadToEnd());
                }
                postBody = sb.ToString();
            }
        }

        public void Tallenna(string filename)
        {
            using (StreamWriter tw = new StreamWriter(filename))
            {
                tw.WriteLine(postTitle);
                tw.WriteLine(postBody);
            }
        }

        public override string ToString()
        {
            return postTitle;
        }
    }
}
